package ray.surface;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import ray.math.Point3;
import ray.math.Vector3;

public class SurfaceTest {
	Sphere testSphere = new Sphere();
	Sphere testSphere2 = new Sphere();
	Box testBox = new Box();
	Vector3 testRay1 = new Vector3();
	Vector3 testRay2 = new Vector3();
	Vector3 testRay3 = new Vector3();
	Vector3 testRay4 = new Vector3();
	
	

	@Before
	public void setup() {
		testSphere.setCenter(new Point3(3,0,0));
		testSphere.setRadius(1);
		testSphere2.setCenter(new Point3(4,0,0));
		testSphere2.setRadius(2);
		testBox.setMinPt(new Point3(2,-1,-1));
		testBox.setMaxPt(new Point3(4,1,1));
		testRay1.set(1,0,0);
		testRay2.set(2,0,0);
		testRay3.set(0,2,0);
		testRay4.set(-1,0,0);
	}
	
	@Test
	public void sphereRayCollisionTest() {
		assertTrue("Result not the expected result using a vector of unit length: " + testSphere.rayCollision(testRay1, new Point3(0,0,0)), 
				testSphere.rayCollision(testRay1, new Point3(0,0,0)) == 2.0 );
		/*assertTrue("Result not the expected result using a vector of arbitrary length: " + testSphere.rayCollision(testRay2, new Point3(0,0,0)), 
				testSphere.rayCollision(testRay2, new Point3(0,0,0)) == 1.0 );*/
		assertTrue("Hit registered when it should not have when using a vector of unit length: " + testSphere.rayCollision(testRay3, new Point3(0,0,0)), 
				testSphere.rayCollision(testRay3, new Point3(0,0,0)) == 0.0 );
		/*assertTrue("Hit registered when it should not have when using a vector of arbitrary length: " + testSphere.rayCollision(testRay4, new Point3(0,0,0)), 
				testSphere.rayCollision(testRay4, new Point3(0,0,0)) == 0.0 );*/
	}
	
	@Test
	public void sphere2RayCollisionTest() {
		assertTrue("Result not the expected result using a vector of unit length: " + testSphere2.rayCollision(testRay1, new Point3(0,0,0)), 
				testSphere2.rayCollision(testRay1, new Point3(0,0,0)) == 2.0 );
	}
	
	/*@Test
	public void sphere2RayCollisionTest1() {
		assertTrue("Result not the expected result using a vector of arbitrary length: " + testSphere2.rayCollision(testRay2, new Point3(0,0,0)), 
				testSphere2.rayCollision(testRay2, new Point3(0,0,0)) == 1.0 );
	}*/
	
	@Test
	public void sphere2RayCollisionTest2() {
		assertTrue("Hit registered when it should not have when using a vector of unit length: " + testSphere2.rayCollision(testRay3, new Point3(0,0,0)), 
				testSphere2.rayCollision(testRay3, new Point3(0,0,0)) == 0.0 );
	}
	
	/*@Test
	public void sphere2RayCollisionTest3() {
		assertTrue("Hit registered when it should not have when using a vector of arbitrary length: " + testSphere2.rayCollision(testRay4, new Point3(0,0,0)), 
				testSphere2.rayCollision(testRay4, new Point3(0,0,0)) == 0.0 );
	}*/
	
	
	@Test
	public void boxRayCollisionTest() {
		assertTrue("Result not the expected result using a vector of unit length: " + testBox.rayCollision(testRay1, new Point3(0,0,0)), 
				testBox.rayCollision(testRay1, new Point3(0,0,0)) == 2.0 );
		assertTrue("Result not the expected result using a vector of arbitrary length: " + testBox.rayCollision(testRay2, new Point3(0,0,0)), 
				testBox.rayCollision(testRay2, new Point3(0,0,0)) == 1.0 );
		assertTrue("Hit registered when it should not have when using a vector of unit length: " + testBox.rayCollision(testRay3, new Point3(0,0,0)), 
				testBox.rayCollision(testRay3, new Point3(0,0,0)) == 0.0 );
		assertTrue("Hit registered when it should not have when using a vector of arbitrary length: " + testBox.rayCollision(testRay4, new Point3(0,0,0)), 
				testBox.rayCollision(testRay4, new Point3(0,0,0)) == 0.0 );
	}

}
